<?php
//require_once dirname(dirname(__DIR__))."/common.php";
require_once dirname(__DIR__)."/login_filter.php";
use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\cls\tom\Tools;
use app\model\Users;
$uuid=$Auth['uuid'];
//$uuid=3;
//分页
$page = isset($_REQUEST["page"]) ? intval($_REQUEST["page"]) : 1;
$page = $page > 0 ? $page : 1;
$pageSize = 200;

//实例化数据库
$db = SysResource::getDB(false);
$Users = new Users($db);
//实例化redis
$redis = SysResource::getRedis();
//查询用户所有的关注和被关注
$uid=sprintf("%d",crc32($uuid));
$key1=REDIS_PREFIX."follow_".$uid;//我的关注
//$key2=REDIS_PREFIX."is_follow_".$uid;//我的粉丝（被关注）
$da4=[];
$da5=[];
//分页去查询用户的关注
$da1=$Users->my_is_follow_list($page,$pageSize,$uuid);

//1.先去redis里查询是否有用户关注
$da2=$redis->hKeys($key1);
$da2="";
if(empty($da2)){
    //为空就去查数据库
    $da2=$Users->follow($uuid);//关注
    if(!empty($da2)){
        foreach($da2 as $k=>$v){
            $da4[]=$v['other_uuid'];
        }
    }
}else{
    $da4=$da2;
}

//2.先去redis里查询是否有粉丝
//$da3=$redis->hKeys($key2);
//if(empty($da3)){
//    $da3=$Users->is_follow($uuid);//被关注
//    if(!empty($da3)){
//        foreach($da3 as $kk=>$vv){
//            $da5[]=$vv['my_uuid'];
//        }
//    }
//}else{
//    $da5=$da3;
//}

if(!empty($da1)){
    foreach($da1 as $kkk=>&$vvv){
        if(in_array($vvv['my_uuid'],$da4)){
            $vvv['guanzhu']= 3;
        }else{
            $vvv['guanzhu']=2;
        }
        if(empty($vvv['test_user_autograph'])){
            $vvv['test_user_autograph']="";
        }
    }
}
//var_dump($da4);
//var_dump($da5);exit;
Response::output(0,"查询成功",$da1);